package com.example.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KafkaProducerService {

    @Autowired
    private KafkaProducer<String, String> producer;

    private static final String TOPIC = "test";

    public void produce(String message) {
        producer.send(new ProducerRecord<>(TOPIC, message));
        System.out.println("Message produced: " + message);
    }
}
